package com.order.controller;

import com.order.domain.TOrder;
import com.order.service.AccountService;
import com.order.service.impl.StorageService;
import com.order.service.impl.TOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import spring.cloud.Utils.R;

/**
 * @author cyt
 * @create 2020-06-07 16:45
 */
@Slf4j
@RequestMapping("/order")
@RestController
public class testController {
    @Autowired
    TOrderService tOrderService;

    /**
     * 下订单->减库存->扣余额->改（订单）状态
     */
    @RequestMapping("/create/{userId}/{productId}/{count}")
    public R createOrder(@PathVariable("userId") String userId,
                         @PathVariable("productId") String productId,
                         @PathVariable("count") String count) {
        // 创建订单
        TOrder order = new TOrder();
        order.setUserId(Integer.parseInt(userId));
        order.setProductId(Integer.parseInt(productId));
        order.setCount(Integer.parseInt(count));
        log.info(order.toString());
        tOrderService.createOrder(order);
        return R.ok();
    }

}
